/**
 * Created by Administrator on 2017/3/7 0007.
 */
var PageInfo= {
    create: function () {
        var page = {};
        var tw_t0,tw_t1,tw_t2,tw_t3,tw_t4,tw_line,tw_whole,tw_bt;

        page.ui=new PIXI.DisplayObjectContainer();
        console.log(resource,resource['assets/images/pageInfo_bg.png'].texture);
        var bg=new PIXI.Sprite(resource['assets/images/pageInfo_bg.png'].texture);
        page.ui.addChild(bg);

        var t0y=159;
        var t0=new PIXI.Sprite(resource['assets/images/pageInfo_t0.png'].texture);
        t0.x=564;
        t0.y=t0y;
        t0.alpha=0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);

        var t1x=207;
        var t1=new PIXI.Sprite(resource['assets/images/pageInfo_t1.png'].texture);
        t1.x=565;
        t1.y=249;
        t1.alpha=0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        var t2=new PIXI.Sprite(resource['assets/images/pageInfo_t2.png'].texture);
        t2.x=566;
        t2.y=387-30;
        t2.alpha=0;
        t2.anchor.set(0.5);
        page.ui.addChild(t2);

        var t3x=78;
        var t3=new PIXI.Sprite(resource['assets/images/pageInfo_t3.png'].texture);
        t3.x=568;
        t3.y=438-30;
        t3.alpha=0;
        t3.anchor.set(0.5);
        page.ui.addChild(t3);

        var t4=new PIXI.Sprite(resource['assets/images/pageInfo_t4.png'].texture);
        t4.x=550;
        t4.y=490-30;
        t4.alpha=0;
        t4.anchor.set(0.5);
        page.ui.addChild(t4);

        var line=new PIXI.Sprite(resource['assets/images/pageInfo_line.png'].texture);
        line.x=568;
        line.y=252;
        line.alpha=0;
        line.anchor.set(0.5);
        page.ui.addChild(line);

        var bt_start=new PIXI.Sprite(resource['assets/images/pageInfo_start.png'].texture);
        bt_start.x=550;
        bt_start.y=590-25;
        bt_start.alpha=0;
        bt_start.anchor.set(0.5);
        page.ui.addChild(bt_start);
        bt_start.interactive=true;
        bt_start.on('pointerdown',function () {
            console.log('1111111111111111')
            bt_start.interactive=false;
            var event = new CustomEvent("Main_GameIn");
            document.dispatchEvent(event);
        });

        var tw_btLoop=new TWEEN.Tween({scaleX:1,scaleY:1,alpha:1})
            .to({scaleY:0.9,scaleX:0.9,alpha:0.5},500)
            .onUpdate(function () {
                bt_start.alpha=this.alpha;
                bt_start.scale.x=this.scaleX;
                bt_start.scale.y=this.scaleY;
            })
            .easing(TWEEN.Easing.Cubic.InOut)
            .repeat(Infinity)
            .yoyo(true);
            // .start();

        page.In=function () {
            if(page.tw_whole)
            {
                page.tw_whole.stop();
                TWEEN.remove(page.tw_whole);
            }

            tw_line=new TWEEN.Tween({alpha:0,scaleX:0})
                .to({alpha:1,scaleX:1},1000)
                .delay(0)
                .onUpdate(function () {
                    // t0.alpha=this.alpha;
                    // t0.x=this.x;
                    line.alpha=this.alpha;
                    line.scale.x=this.scaleX;

                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();

            tw_t1=new TWEEN.Tween({alpha:0,scaleX:0})
                .to({alpha:1,scaleX:1},1000)
                .delay(200)
                .onUpdate(function () {
                    t1.alpha=this.alpha;
                    t1.scale.x=this.scaleX;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();

            tw_t0=new TWEEN.Tween({alpha:0,y:t0y+30})
                .to({alpha:1,y:t0y},1000)
                .delay(1000)
                .onUpdate(function () {
                    t0.alpha=this.alpha;
                    t0.y=this.y;
                })
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t2=new TWEEN.Tween({alpha:0,scaleX:0,scaleY:1})
                .to({alpha:1,scaleX:1,scaleY:1},1000)
                .onUpdate(function () {
                    t2.scale.x=this.scaleX;
                    t2.scale.y=this.scaleY;
                    t2.alpha=this.alpha;
                })
                .delay(1200)
                .easing(TWEEN.Easing.Back.Out)
                .start();

            tw_t3=new TWEEN.Tween({alpha:0,scaleX:0,scaleY:1})
                .to({alpha:1,scaleX:1,scaleY:1},1000)
                .onUpdate(function () {
                    t3.scale.x=this.scaleX;
                    t3.scale.y=this.scaleY;
                    t3.alpha=this.alpha;
                })
                .delay(1400)
                .easing(TWEEN.Easing.Back.Out)
                .start();
            tw_t4=new TWEEN.Tween({alpha:0,scaleX:0,scaleY:1})
                .to({alpha:1,scaleX:1,scaleY:1},1000)
                .onUpdate(function () {
                    t4.scale.x=this.scaleX;
                    t4.scale.y=this.scaleY;
                    t4.alpha=this.alpha;
                })
                .delay(1600)
                .easing(TWEEN.Easing.Back.Out)
                .start();

            if(tw_btLoop)
            {
                tw_btLoop.stop();
            }

            tw_bt=new TWEEN.Tween({alpha:0,scaleX:0,scaleY:0})
                .to({alpha:1,scaleX:1,scaleY:1},1000)
                .onUpdate(function () {
                    bt_start.scale.x=this.scaleX;
                    bt_start.scale.y=this.scaleY;
                    bt_start.alpha=this.alpha;
                })
                .onComplete(function () {
                    tw_btLoop.start();
                })
                .delay(2000)
                .easing(TWEEN.Easing.Back.Out)
                .start();
        }
        page.Out=function () {
            if(tw_t0)
            {
                tw_t0.stop();
                TWEEN.remove(tw_t0);
            }
            if(tw_t1)
            {
                tw_t1.stop();
                TWEEN.remove(tw_t1);
            }
            if(tw_t2)
            {
                tw_t2.stop();
                TWEEN.remove(tw_t2);
            }
            if(tw_t3)
            {
                tw_t3.stop();
                TWEEN.remove(tw_t3);
            }
            if(tw_t4)
            {
                tw_t4.stop();
                TWEEN.remove(tw_t4);
            }
            if(tw_line)
            {
                tw_line.stop();
                TWEEN.remove(tw_line);
            }
            if(tw_bt)
            {
                tw_t4.stop();
                TWEEN.remove(tw_bt);
            }
            if(tw_btLoop)
            {
                tw_btLoop.stop();
            }
            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},400)
                .onUpdate(function () {
                    page.ui.alpha=this.alpha;
                })
                .onComplete(function () {
                    page.ui.alpha=1;
                    t0.alpha=0;
                    t1.alpha=0;
                    t2.alpha=0;
                    t3.alpha=0;
                    t4.alpha=0;
                    line.alpha=0;
                    bt_start.alpha=0;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }


        return page;
    }

}
